package main
import (
	"fmt"
)
type author struct {
	firstName string
	lastName string
	bio string
}
func (a author) fullName() string {
	return fmt.Sprintf("%s %s", a.firstName, a.lastName)
}
type post struct {
	title string
	content string
	author
}
func (p post) details() {
	fmt.Println("Title: ", p.title)
	fmt.Println("Content: ", p.content)
	fmt.Println("Author: ", p.fullName())
	fmt.Println("Bio: ", p.bio)
}
// 结构体切片的嵌套
type website struct {
	posts []post
}
func (w website) content(){
	fmt.Println("======== Contents of Website ==========")
	for _, v := range w.posts {
		v.details()
		fmt.Println()
	}
}


// 27.组合取代继承
func main(){
	// 通过嵌套结构体进行组合
	author1 := author{"yang", "hao", "go 信息文章"}
	post1 := post{"通过嵌套结构体进行组合","Go supports composition instead of inheritance", author1}
	post1.details()

	// 结构体切片的嵌套
	post2 := post{"===Struct instead of Classes in Go", "===Go does not support classes but methods can be added to structs", author1}
	post3 := post{"===Concurrency", "===Go is a concurrent language and not a parallel one", author1}
	w := website{
		posts: []post{post1, post2, post3},
	}
	w.content()

}
